#include "stdafx.h"
#include <d3dx9effect.h>
#include "wheel_seter.h"
#include "ltbasedefs.h"
#include "lteffectimpl.h"
#include "../ltclientshell.h"
#include <iltclient.h>
#include "../shader_mgr.h"
#include "shader_light_system.h"
#include "../d3d_texture_manager.h"

void wheel_seter::set_args( LTEffectShader *pEffect,const LTShaderDeviceState &ShaderDeviceState )
{
	ShaderDeviceState.GetMatrix(LTShaderDeviceState::LTMatrixType::MATRIXTYPE_VIEW,false, m_view) ;
	LTShaderDeviceState::LTLightDesc dect ;
	//for(int i = 0 ;i < 3 ; i++) {
	LTVector pos ;
	g_pLTClient->GetObjectPos(get_obj(), &pos) ;

	shader_manager* mgr = get_shader_manager() ;
	mgr->light_system()->range_light_by_distance(pos) ;
	mgr->light_system()->use_lights(pEffect, m_factor, m_light_pos, m_radius, 4);
	/*
	if(dect.m_Active) {
	float position[4] ;
	position[0] = dect.m_Position.x ;
	position[1] = dect.m_Position.y ;
	position[2] = dect.m_Position.z ;
	position[3] = 0.0 ;
	pEffect->SetFloatArray("g_light[0].position", position, 3) ;
	position[0] = dect.m_Diffuse.r ;
	position[1] = dect.m_Diffuse.g ;
	position[2] = dect.m_Diffuse.b ;
	position[3] = dect.m_Diffuse.a ;
	pEffect->SetFloatArray("g_light[0].color", position, 4) ;

	}
	*/
	//}


	ShaderDeviceState.GetMatrix(LTShaderDeviceState::LTMatrixType::MATRIXTYPE_WORLD0, false, m_world);
	ShaderDeviceState.GetMatrix(LTShaderDeviceState::LTMatrixType::MATRIXTYPE_VIEWPROJECTION, false, m_view_proj);
	pEffect->SetMatrix("World",*m_world);
	pEffect->SetMatrix("ViewProj",*m_view_proj);
	m_world->Inverse() ;
	pEffect->SetMatrix("WorldInv", *m_world) ;
	m_view->Inverse() ;
	pEffect->SetMatrix("ViewInv", *m_view) ;

	pEffect->SetVector("tail_light_color",m_tail_color);

	//pEffect->SetVector("lightpos",m_light_pos);
	ID3DXEffect* pD3dEffect = ((LTEffectImpl*)(pEffect))->GetEffect() ;
	D3DXHANDLE handleCubeMap ;
	IDirect3DCubeTexture9* ttx  = 0 ;



}

void wheel_seter::set_light_pos( const LTVector& _pos, float factor, float radius )
{
	m_light_pos[0]=_pos.x;
	m_light_pos[1]=_pos.y;
	m_light_pos[2]=_pos.z;
	m_light_pos[3]=1;
	m_factor = factor ;
	m_radius = radius ;

}

void wheel_seter::set_tail_color( float _r/*=0.0f*/,float _g/*=0.0f*/,float _b/*=0.0f*/ )
{
	m_tail_color[0]=_r;
	m_tail_color[1]=_g;
	m_tail_color[2]=_b;

}

wheel_seter::wheel_seter( shader_manager* mgr ):
arg_seter(mgr),
m_factor(1.0f),
m_tex_mgr(mgr->texture_manager())
{
	m_light_pos[0] = -16.0f ;
	m_light_pos[1] = 52.0f;
	m_light_pos[2] = -256.0f ;

	m_tail_color[0]=m_tail_color[1]=m_tail_color[2]=0.0f;
	m_tail_color[3]=1.0f;


}